<template lang="pug">
    .root-header(v-if="!hideMenus")
        header
            //i-menu(:route="$route" :menus="menusList")
            .up-right
                el-dropdown.login(@command='userAction')
                    img.avatar(src="~images/header/avatar.svg")
                    el-dropdown-menu(slot='dropdown')
                        el-dropdown-item(command='logout') 登出
</template>

<script>
import { mapState } from 'vuex'
import config from '@/config'
import { AJAX } from '@utils/request'

export default {
    name: 'AppHeader',
    components: {
        // IMenu,
    },
    data() {
        return {}
    },
    methods: {
        userAction(key) {
            if (key === 'logout') {
                this.loginOut() // ----是否真的退出还是只是跳转到登录页面？当前跳转到登录页面
            }
        },
        // 登出
        async loginOut() {
            await AJAX.get(config.userLogoutUrl)
            window.location.href = location.origin + '/cas/logout'
        },
    },
    computed: {
        ...mapState({
            hideMenus: state => state.app.hideMenus,
            menusList: state => state.app.menusList,
        }),
    },
    created() {
        console.log(config)
    },
}
</script>

<style lang="scss"></style>
